package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ngc.mall.domain.MemberBenefitDomain;
import com.ngc.mall.domain.MemberLevelDomain;
import com.ngc.mall.mapper.MemberLevelMapper;
import com.ngc.mall.service.IMemberBenefitService;
import com.ngc.mall.service.IMemberLevelService;
import com.ngc.mall.vo.MemberLevelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 会员等级
 * @author: chenxiaolin
 * @date 2023/9/3 1:17
**/
@Service
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper,MemberLevelDomain> implements IMemberLevelService  {

    @Autowired
    private IMemberBenefitService iMemberBenefitService;
    /**
     * 设置会员等级
     * @param memberLevelList
     * @return
     */
    @Override
    public Boolean updateMemberLevel(List<MemberLevelDomain> memberLevelList) {
        return super.updateBatchById(memberLevelList);
    }

    /**
     * 查看所有会员等级
     * @return
     */
    @Override
    public List<MemberLevelVO> findMemberLevel() {
        List<MemberLevelDomain> list=super.list();
        List<MemberLevelVO> memberLevelVOList=new ArrayList<>();
        for(MemberLevelDomain domain:list){
            List<MemberBenefitDomain> memberBenefitList=iMemberBenefitService.getMemberBenefitListByLevelId(domain.getId());
            MemberLevelVO vo= MemberLevelVO.builder().id(domain.getId()).amount(domain.getAmount()).img(domain.getImg()).name(domain.getName()).sign(domain.getSign()).memberBenefitList(memberBenefitList).build();
            memberLevelVOList.add(vo);
        }
       return memberLevelVOList;
    }


    @Override
    public MemberLevelVO getDetailById(Long id){
        MemberLevelDomain domain=super.getById(id);
        List<MemberBenefitDomain> memberBenefitList=iMemberBenefitService.getMemberBenefitListByLevelId(domain.getId());
        MemberLevelVO vo= MemberLevelVO.builder().id(domain.getId()).amount(domain.getAmount()).img(domain.getImg()).name(domain.getName()).sign(domain.getSign()).memberBenefitList(memberBenefitList).build();

        return vo;
    }


}
